﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pic_downall.aspx.cs" Inherits="admin_pic_downall" %>

<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="Stylesheet" rev="Stylesheet" href="images/style.css" />
    <script type="text/javascript" src="../Scripts/jquery.js"></script>
    <script type="text/javascript" src="../Scripts/jquery.progressbar.min.js"></script>
    <script type="text/javascript">
        var downloadtp = function (zjid) {
            var urls = document.getElementById("no_tpurl" + zjid).value.split('|');
            var tps = document.getElementById("tps" + zjid).value;
            var tpadd = document.getElementById("tpadd" + zjid).value;
            for (var i = 0; i < urls.length; i++) {
                if (urls[i] != null && urls[i] != "") {
                    $.getJSON("pic_down.aspx?_t=" + new Date(), { url: urls[i], tpadd: tpadd,server:$("#server").val() },
                    function (data) {
                        if (data.success == "true") {
                            var obj = document.getElementById('tpcount' + zjid);
                            var tpcount = parseInt(obj.innerText) + 1;
                            obj.innerText = tpcount;
                            $('#pb' + zjid).progressBar(Math.floor(100 * tpcount / tps));
                        } else {
                            document.getElementById("errorText").innerText += data.error + "<br>";
                        }
                    });
                }
            }
        }

        var mulidownloadtp = function () {
            if (confirm('确定批量下载!?')) {
                var checkboxs = document.getElementsByName("zjcheckbox");
                for (var i = 0; i < checkboxs.length; i++) {
                    if (checkboxs[i].checked) {
                        downloadtp(checkboxs[i].value);
                    }
                }
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div style="text-align: center">
        <h2>
            章节下载</h2>
        <p>漫画服务器：
            <select id="server">
                <option value="mh2" selected="selected">mh2</option>
                <option value="mh">mh</option>
                <option value="www">www</option>
            </select></p>
        <asp:GridView ID="zjGridView" runat="server" EnableModelValidation="True" AutoGenerateColumns="False"
            DataKeyNames="id" CellPadding="3" CellSpacing="1" BackColor="#CCCCCC" 
            Width="98%" BorderWidth="0">
            <HeaderStyle BackColor="#e7e7e7" />
            <PagerSettings FirstPageText="首页" LastPageText="末页" NextPageText="下页" PreviousPageText="上页"
                Mode="Numeric" />
            <RowStyle BackColor="#FFFFFF" HorizontalAlign="Left" />
            <Columns>
                <asp:TemplateField HeaderText="下载">
                    <ItemTemplate>
                        <input type="checkbox" name="zjcheckbox" value="<%# Eval("id") %>" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="id" HeaderText="编码" InsertVisible="False" ReadOnly="True"
                    SortExpression="id" ItemStyle-Width="4%">
                    <ItemStyle Width="4%"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="zjmc" HeaderText="名称" SortExpression="zjmc" ItemStyle-Width="17%">
                    <ItemStyle Width="17%"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="tpadd" HeaderText="路径" SortExpression="tpadd" />
                <asp:BoundField DataField="tps" HeaderText="数量" SortExpression="tps" />
                <asp:TemplateField HeaderText="下载">
                    <ItemTemplate>
                        <span id='tpcount<%# Eval("id") %>'>
                            <%# Eval("tpcount")%></span>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="进度" ItemStyle-Width="17%">
                    <ItemTemplate>
                        `
                        <input id="no_tpurl<%# Eval("id") %>" type="hidden" value="<%# Eval("no_tpurl") %>" />
                        <input id="tps<%# Eval("id") %>" type="hidden" value="<%# Eval("tps") %>" />
                        <input id="tpadd<%# Eval("id") %>" type="hidden" value="<%# Eval("tpadd") %>" />
                        <span class="progressBar" id='pb<%# Eval("id") %>'></span>
                        <script type="text/javascript">
                    var per = Math.floor(<%# Eval("tpcount") %>/ <%# Eval("tps") %>* 100);
                    $('#pb<%# Eval("id") %>').progressBar(per,{barImage: '../images/progressbar/progressbg_yellow.gif' });
                        </script>
                    </ItemTemplate>
                    <ItemStyle Width="17%"></ItemStyle>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="操作">
                    <ItemTemplate>
                        <a href="#" onclick="downloadtp(<%# Eval("id") %>)">下载</a> <a href="zj_add.asp?id=<%# Eval("id") %>&comicid=<%= Request.QueryString["id"] %>&cjcomicid=42194&act=edit">
                            修改</a>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
        <webdiyer:AspNetPager ID="AspNetPager1" runat="server" HorizontalAlign="Right" 
            UrlPaging="True" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" 
            onpagechanging="AspNetPager1_PageChanging" PrevPageText="上一页">
        </webdiyer:AspNetPager>
        <input name="act" type="button" class="Submit" id="act" title="批量下载" onclick="mulidownloadtp()"
            value="批量下载" />
        <div id="errorText" style="font-size: small; color: Red;">
        </div>
    </div>
    </form>
</body>
</html>
